package com.cn.txx.test.aqs;

import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownLatchExample1 {

	// 请求数 即线程数
	private final static int threadCount = 200;

	private static int resulet = 0;

	public static void main(String[] args) throws InterruptedException {
		long startime = new Date().getTime();
		for (int i = 0; i < 100; i++) {
			test();
		}
		long endtime = new Date().getTime();
		System.out.println(endtime - startime);
	}

	public static synchronized void getresulet() {
		resulet++;
	}

	public static void test() throws InterruptedException {
		resulet = 0;
		ExecutorService executorService = Executors.newCachedThreadPool();

		final CountDownLatch countDownLatch = new CountDownLatch(threadCount);

		for (int i = 0; i < threadCount; i++) {
			executorService.execute(new Runnable() {
				public void run() {
					getresulet();
					countDownLatch.countDown();
				}
			});
		}
		countDownLatch.await();
		System.out.println(resulet);
		executorService.shutdown();
	}
}
